Hello. I’ve encountered a strange issue with TimelineView and wanted to report it.
The following code runs without any problems:
// Example 1.
struct ContentView: View {
var body: some View {
TimelineView(.everyMinute) { _ in
List {
TimelineView(.everyMinute) { _ in
Text("Hello")
}
}
}
}
}
However, the code below causes the CPU usage to spike to 100%, and the screen displays a blank view:
// Example 2.
struct ContentView: View {
var body: some View {
TimelineView(.everyMinute) { _ in
List {
TimelineView(.everyMinute) { _ in
text
}
}
}
}
var text: some View {
Text("Hello")
}
}
The same issue occurs with the following code:
// Example 3.
struct MyTextView: View {
var body: some View {
Text("Hello")
}
}
struct ContentView: View {
var body: some View {
TimelineView(.everyMinute) { _ in
List {
TimelineView(.everyMinute) { _ in
MyTextView()
}
}
}
}
}
Replacing List with LazyVStack and ForEach resolves the hang issue, but I need to use List because I rely on the swipeActions().
Does anyone have insights or suggestions on how to address this issue?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
To apply custom transition animations, I implemented a UIViewControllerRepresentable wrapping UINavigationController instead of using NavigationStack.
The navigation stack pops correctly with DismissAction.
However, when I call DismissAction after presenting my CustomNavigationStack with fullScreenCover(isPresented:onDismiss:content:), it doesn't work.
I suspect that the DismissAction implementation does not handle this case. Is there a workaround for this?
Below is a simple reproduction code:
struct ChildView: View {
@Environment(\.dismiss) private var dismiss
var body: some View {
Button {
dismiss()
} label: {
Text(verbatim: "Dismiss!!")
.background(Color.yellow)
}
}
}
struct CustomSimpleVC: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIHostingController<ChildView> {
let vc = UIHostingController(rootView: ChildView())
vc.view.backgroundColor = .green
return vc
}
func updateUIViewController(_ uiViewController: UIHostingController<ChildView>, context: Context) {}
}
struct CustomContainerVC: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
let childVC = UIHostingController(rootView: ChildView())
childVC.view.backgroundColor = .blue
let vc = UIViewController()
vc.addChild(childVC)
vc.view.addSubview(childVC.view)
childVC.view.frame = vc.view.bounds
childVC.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
childVC.didMove(toParent: vc)
return vc
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
struct CustomNavigationVC: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UINavigationController {
let childVC = UIHostingController(rootView: ChildView())
childVC.view.backgroundColor = .red
let childVC2 = UIHostingController(rootView: ChildView())
childVC2.view.backgroundColor = .gray
let navVC = UINavigationController()
navVC.viewControllers = [childVC, childVC2]
return navVC
}
func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {}
}
struct ContentView: View {
@State private var isNextPresented: Bool = false
var body: some View {
VStack {
Button {
isNextPresented = true
} label: {
Text(verbatim: "present")
}
}
.fullScreenCover(isPresented: $isNextPresented, content: {
VStack {
CustomSimpleVC() // Works
CustomContainerVC() // Works
CustomNavigationVC() // Does not work
}
})
}
}
#Preview {
ContentView()
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
It seems that Xcode gets confused when there is another format specifier before a plural variable.
As shown in the screenshot, %#@VARIABLE@ %f works fine, but an error occurs with %f %#@VARIABLE@.